#ifndef VALIDATORFACTORY_H
#define VALIDATORFACTORY_H
#include "stringvalidator.h"
#include "prefixvalidator.h"
#include "suffixvalidator.h"
#include "lengthvalidator.h"
#include "exactvalidator.h"
#include "containsvalidator.h"
#include "regexvalidator.h"
#include "compositevalidator.h"
#include <QString>

class ValidatorFactory
{
public:
    ValidatorFactory();
    // 创建前缀验证器
    static StringValidator::ValidatorPtr createPrefixValidator(
        const QString& prefix,
        const QString& errorMsg = "String must start with '%1'") {
        return std::make_shared<PrefixValidator>(prefix, errorMsg);
    }

    // 创建后缀验证器
    static StringValidator::ValidatorPtr createSuffixValidator(
        const QString& suffix,
        const QString& errorMsg = "String must end with '%1'") {
        return std::make_shared<SuffixValidator>(suffix, errorMsg);
    }

    // 创建长度验证器
    static StringValidator::ValidatorPtr createLengthValidator(
        int min, int max = -1,
        const QString& errorMsg = "Length %1 is invalid (expected %2-%3 characters)") {
        return std::make_shared<LengthValidator>(min, max, errorMsg);
    }

    // 创建全匹配验证器
    static StringValidator::ValidatorPtr createExactValidator(
        const QString& pattern,
        const QString& errorMsg = "String must exactly match '%1'") {
        return std::make_shared<ExactValidator>(pattern, errorMsg);
    }

    // 创建部分匹配验证器
    static StringValidator::ValidatorPtr createContainsValidator(
        const QString& substring,
        const QString& errorMsg = "String must contain '%1'") {
        return std::make_shared<ContainsValidator>(substring, errorMsg);
    }

    // 创建正则验证器
    static StringValidator::ValidatorPtr createRegexValidator(
        const QString& pattern,
        const QString& errorMsg = "String must match pattern '%1'") {
        return std::make_shared<RegexValidator>(pattern, errorMsg);
    }

    // 创建AND组合验证器
    static StringValidator::ValidatorPtr createAndValidator(
        const std::vector<StringValidator::ValidatorPtr>& validators,
        const QString& errorMsg = "All validations failed") {
        auto validator = std::make_shared<CompositeValidator>(CompositeValidator::AND, errorMsg);
        for (const auto& v : validators) {
            validator->addValidator(v);
        }
        return validator;
    }

    // 创建OR组合验证器
    static StringValidator::ValidatorPtr createOrValidator(
        const std::vector<StringValidator::ValidatorPtr>& validators,
        const QString& errorMsg = "None of the validations passed") {
        auto validator = std::make_shared<CompositeValidator>(CompositeValidator::OR, errorMsg);
        for (const auto& v : validators) {
            validator->addValidator(v);
        }
        return validator;
    }
};

#endif // VALIDATORFACTORY_H
